package com.wntms.wy.dao;

import com.wntms.wy.pojo.CarrigeContract;
import com.wntms.wy.pojo.CollectionSettle;
import com.wntms.wy.pojo.CustomerAccept;
import com.wntms.wy.pojo.FreightContract;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CustomerDao {

    //判断该货运单是否存在
    @Select("select count(*) from freight_contract where fid=#{fid}")
    int freightContractCountFindByFid(String fid);
    //客户操作验收单
    //首先就要先查一下货运单，看一下paymment是否为null
    //1是null:说明没有代收业务，则直接进行增加客户验收单操作
    //2不是null：再查看ispayment是true还说false 。为false，增让客户先去结算管理支付代收货款。为true说明已支付代收货款，可以进行增加验收操作
    //增：前端应传回来 fid货运编号、ispass是否验收成功、和客户验收时间
    @Select("select * from freight_contract where fid=#{fid}")
    FreightContract freightContractFindByfid(String fid);
    @Select("select count(*) from collection_settle where fid=#{fid}")
    int findCSCount(String fid);
    @Select("select * from collection_settle where fid=#{fid}")
    CollectionSettle collectionSettleFindByfid(String fid);
    @Select("select * from carriage_contract where fid=#{fid}")
    CarrigeContract carriageContractFindByFid(String fid);
    @Insert("insert into customer_accept (ispass,cid,fid,accept_time,name) values (#{ispass},#{cid},#{fid},#{accepttime},#{name})")
    int addCustomerAccept(CustomerAccept customerAccept);

    //根据cid 去修改运输单里的状态为4表示为司机回执
    @Update("update freight_status set status=5 where id=#{fsid}")
    int updateFreightStatus3(Integer fsid);


    //删：前端传回来caid
    @Delete("delete from customer_accept where caid=#{caid}")
    int deleteCustomerAcceptByCaid(Integer caid);

    //改;只能改 是否通过ispass,客户收货时间,客户姓名
    @Update("update customer_accept set ispass=#{ispass},accept_time=#{accepttime},name=#{name} where caid=#{caid}")
    int updateCustomerAccept(CustomerAccept customerAccept);

    //查询说有客户验收单
    @Select("select * from customer_accept")
    List<CustomerAccept> findAllCustomerAccept();
}
